using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class DriftBottleSettingPage : BasePage
	{
		private const string TAG = "DriftBottleSettingPage";
		private EventWatcher mWatchContactListChange;
		private bool mFlagAccountStatusChanged;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal DriftBottleSetHeadCtrl ctrlSetHead;
		internal TextBlock txtSetHead;
		internal MMToggleSwitch switchDisplay;
		internal StackPanel panelDisplay;
		private bool _contentLoaded;
		public DriftBottleSettingPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("DriftBottleSettingPage", "Page_Loaded");
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("DriftBottleSettingPage", "Page_Loaded");
			if (this.mFlagAccountStatusChanged)
			{
				AccountMgr.ShowBottleInChat = !AccountMgr.ShowBottleInChat;
				if (AccountMgr.ShowBottleInChat)
				{
					BConversationMgr.ShowBConvInMainPage(false);
				}
				else
				{
					BConversationMgr.HideBConvInMainPage();
				}
				ServiceCenter.sceneNewSync.doScene(1, syncScene.MM_NEWSYNC_SCENE_OTHER);
				this.mFlagAccountStatusChanged = false;
			}
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("DriftBottleSettingPage", "OnPageIn");
			this.ctrlSetHead.Init(new UITaskDlgEx(this.setHeadCtrlHandler));
			this.initSwitch();
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("DriftBottleSettingPage", "OnPageOut");
			this.ctrlSetHead.UnInit();
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("DriftBottleSettingPage", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatchContactListChange == null)
			{
				this.mWatchContactListChange = new EventWatcher(this, this, new EventHandlerDelegate(this.OnContactChange));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchContactListChange);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchContactListChange != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchContactListChange);
				this.mWatchContactListChange = null;
			}
		}
		private void OnContactChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
		}
		private void btnSetHead_Click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/Plugin/DriftBottle/UI/SetDriftBottleHead.xaml", null, false);
		}
		private void checkedStateChanged(object sender, bool isCheckOn)
		{
			if (this.mFlagAccountStatusChanged)
			{
				this.mFlagAccountStatusChanged = false;
				return;
			}
			this.mFlagAccountStatusChanged = true;
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		private void setHeadStart()
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.Set_Personal_SendingImage, null, false, false, null);
		}
		private void setHeadEnd()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		private void setHeadCtrlHandler(object object_0)
		{
			if (object_0 == null)
			{
				return;
			}
			BtleSetHeadOpKind btleSetHeadOpKind = (BtleSetHeadOpKind)object_0;
			if (BtleSetHeadOpKind.OpKind_SetStart == btleSetHeadOpKind)
			{
				this.setHeadStart();
				return;
			}
			if (BtleSetHeadOpKind.OpKind_SetEnd == btleSetHeadOpKind)
			{
				this.setHeadEnd();
			}
		}
		private void initSwitch()
		{
			this.switchDisplay.Text = strings.Setting_PluginsShowBottleInMainFrame;
			if (!BConversationMgr.IsShowBConvInMainPage())
			{
				this.switchDisplay.IsChecked = false;
			}
			else
			{
				this.switchDisplay.IsChecked = true;
			}
			this.switchDisplay.onToggleStateChanged = new OnToggleStateChanged(this.checkedStateChanged);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/DriftBottle/UI/DriftBottleSettingPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.ctrlSetHead = (DriftBottleSetHeadCtrl)base.FindName("ctrlSetHead");
			this.txtSetHead = (TextBlock)base.FindName("txtSetHead");
			this.switchDisplay = (MMToggleSwitch)base.FindName("switchDisplay");
			this.panelDisplay = (StackPanel)base.FindName("panelDisplay");
		}
	}
}
